package com.ruoyi.novel.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.novel.service.CollectionService;
import org.apache.ibatis.annotations.Delete;
import org.hibernate.validator.constraints.ParameterScriptAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 收藏Controller
 */
@RestController
@RequestMapping("/collection")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;
    /**
     * 添加收藏
     */
    @PostMapping("/add")
    public AjaxResult addCollection(@RequestParam("userId") Long userId, @RequestParam("novelName") String novelName){
        return AjaxResult.success(collectionService.addCollection(userId, novelName));
    }
    /**
     * 取消收藏
     */
    @DeleteMapping("/cancel")
    public AjaxResult cancelCollection(@RequestParam("userId") Long userId, @RequestParam("novelName") String novelName) {
        return AjaxResult.success(collectionService.cancelCollection(userId, novelName));
    }
    /**
     * 根据用户id查询是否已经收藏这本书
     */
    @PostMapping("/isCollection")
    public AjaxResult isCollection(@RequestParam("userId") Long userId, @RequestParam("novelName") String novelName){
        return AjaxResult.success(collectionService.isCollection(userId, novelName));
    }
}
